<template>
  <div class="todo-app">
    <h1>Todo List</h1>
    <div class="todo-send">
      <div>
        <el-input data-test="messageText" v-model="inputValue" placeholder="添加一个任务..." @change="save"></el-input>
      </div>
    </div>
    <div class="todo-list">
      <div>
        <ul v-for="(item,index) in items" :key="index">
          <li><span>{{ item }}</span><a data-test="deleteItem" class="delete" @click="deleteItem(index)" href="javascript:;">x</a></li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "ToDoList",
  data() {
    return {
      inputValue: "",
      items: []
    };
  },
  methods: {
    save() {
      this.items.push(this.inputValue);
      this.inputValue = "";
    },
    deleteItem(index) {
      this.items.splice(index, 1);
    }
  }

};
</script>

<style lang="scss">
.todo-app {
  text-align: center;
  width: 1226px;
  height: 900px;

  .todo-send {
    width: 400px;
    height: 50px;
    margin: 10px auto;

    input {
      margin-right: 10px;
    }
  }

  .todo-list {
    width: 400px;
    margin: 10px auto;
    text-align: left;

    ul {
      li {
        span {
          display: inline-block;
          float: left;
          width: 350px;

          .delete {
            width: 10px;
            cursor: pointer;
            margin-right: 0;
          }
        }
      }
    }
  }
}
</style>
